package megasena;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class MegaSena extends JFrame implements ActionListener{
    JButton btn1, btn2, btn3, btn4, btn5, btn6, btn7;
    JPanel p1;
    
    private MegaSena() {
        btn1 = new JButton("00");
        btn2 = new JButton("00");
        btn3 = new JButton("00");
        btn4 = new JButton("00");
        btn5 = new JButton("00");
        btn6 = new JButton("00");
        btn7 = new JButton("Gerar");
        
        p1 = new JPanel(new GridLayout(1,6));
        p1.add(btn1);p1.add(btn2);p1.add(btn3);
        p1.add(btn4);p1.add(btn5);p1.add(btn6);
        
        setVisible(true);
        setLocation(300, 300);
        setTitle("Mega Sena");
        setLayout(new GridLayout(2,1));
        setDefaultCloseOperation(3);
        add(p1);
        add(btn7);
        pack();
        
        btn7.addActionListener(this);
        }
    
    @Override
    public void actionPerformed(ActionEvent evt)
    {
        if (evt.getSource() == btn7)
        {
            enumeraBotoes(geraNumeros());
        }
    }
    
    private void enumeraBotoes(int[] numeros)
    {
        btn1.setText(Integer.toString(numeros[0]));
        btn2.setText(Integer.toString(numeros[1]));
        btn3.setText(Integer.toString(numeros[2]));
        btn4.setText(Integer.toString(numeros[3]));
        btn5.setText(Integer.toString(numeros[4]));
        btn6.setText(Integer.toString(numeros[5]));
    }
    
    private int[] geraNumeros()
    {
        int numeros[] = new int[6];
        Random r = new Random();
        for (int i=0; i < 6; i++)
        {
            numeros[i] = r.nextInt(60);
            numeros[i]++;
        }
        return numeros;
    }
    
    public static void main(String[] args) {
        MegaSena megasena = new MegaSena();
    }
}